<template>
	<view class="top-fixed">
		<u-button class="add-btn" type="primary" plain size="medium" @click="toRelationAdd">新 增</u-button>
	</view>
	<view class="list safe-bottom-distance" v-if="list.length">
		<navigator hover-class="none" :url="`./relationAdd?id=${item.id}&userId=${item.userId}`" class="list-item" v-for="item in list" :key="item.id">
			<view class="list-item__top">
				<view class="relation-name">
					{{item.name}}
				</view>
				<view class="relation-type">
					{{relationTypeFilter(item.type)}}
				</view>
			</view>
			<view class="other-info">
				<view class="info-item">
					<view class="label">
						性别
					</view>
					<view class="value">
						{{item.sex===1?'男':'女'}}
					</view>
				</view>
			</view>
			<view class="other-info">
				<view class="info-item">
					<view class="label">
						手机号
					</view>
					<view class="value">
						{{item.phone}}
					</view>
				</view>
			</view>
			<view class="other-info">
				<view class="info-item">
					<view class="label">
						居住地址
					</view>
					<view class="value">
						{{item.address}}
					</view>
				</view>
			</view>
			<view class="other-info">
				<view class="info-item">
					<view class="label">
						单位名称
					</view>
					<view class="value">
						{{item.company}}
					</view>
				</view>
			</view>
		</navigator>
	</view>
	<view v-else class="empty-container">
		<u-empty text="数据为空" mode="list"></u-empty>
	</view>

</template>
<script setup>
	import {ref,reactive,unref} from "vue"
	import {onReady,onLoad,onReachBottom} from "@dcloudio/uni-app"
	import personnelApi from "@/api/personnel"
	const list = ref([])
	const params = {
		pageNo:1,
		pageSize:10
	}
	let totalPage = 0
	const toRelationAdd = () => {
		uni.navigateTo({
			url: "./relationAdd"
		})
	}
	const relationTypeFilter = (type)=>{
		 switch(type){
		    case 1:
		      return "配偶"
		    case 2:
		      return "儿子"
		    case 3:
		      return "女儿"
		    case 4:
		      return "儿媳妇"
		    case 5:
		      return "女婿"
		    case 6:
		      return "孙子"
		    case 7:
		      return "孙女"
		    case 8:
		      return "孙媳妇"
		    case 9:
		      return "孙女婿"
		      case 10:
		      return "亲戚"
		    case 11:
		      return "同事"
		    case 12:
		      return "邻居"
		    case 13:
		      return "朋友"
			}
	}
	const getData = async ()=>{
		const {data} = await personnelApi.getPersonFamilyList(params)
		totalPage = data.totalPage
		list.value = params.pageNo==1?data.list:unref(list.value).concat(data.list)
	}
	onReachBottom(()=>{
		if(params.pageNo>=totalPage) return
		params.pageNo++
		getData()
	})
	onLoad(()=>{
		uni.$on("getRelationList",()=>{
			params.pageNo = 1
			getData()
		})
		getData()
	})
</script>

<style lang="scss" scoped>
	.top-fixed {
		position: sticky;
		// width: 100%;
		padding: 20rpx;
		text-align: end;
		background-color: #f5f5f5;

		.add-btn {
			:deep(button) {
				height: 69rpx;
				padding: 3rpx 40rpx;
			}
		}
	}
	.list{
		width: 97vw;
		margin: 0 auto 16rpx;
	}
	.list-item {
		border-radius: 20rpx;
		box-shadow: 0 0 20rpx rgba(10, 10, 10, .1);
		box-sizing: border-box;
		padding: 20rpx;
		overflow: hidden;
		margin-bottom: 20rpx;

		.list-item__top {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-bottom: 15rpx;
			margin-bottom: 15rpx;
			border-bottom: 1rpx solid rgb(240, 239, 239);
		}

		.relation-name {
			font-size: 32rpx;
			font-weight: bold;
		}

		.relation-type {
			background-color: $theme-bg-color;
			color: white;
			height: 60rpx;
			line-height: 60rpx;
			padding: 0 30rpx;
			border-top-left-radius: 30rpx;
			border-bottom-left-radius: 30rpx;
		}

		.info-item {
			color: rgb(90, 87, 87);
			font-size: 29rpx;
			display: flex;

			.label {
				width: 150rpx;
			}

			.value {
				flex: 1;
			}
		}
	}

	.empty-container {
		width: 100%;
		height: 100%;
		position: fixed;
		z-index: -1;
	}
</style>
